package com.yhty.web.action;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yhty.model.WeDefine;
import com.yhty.model.WeList;
import com.yhty.model.WeMonth;
import com.yhty.service.WeManager;
import com.yhty.utils.DateUtil;

/**
 * 水电信息action
 * @author RoySong
 * 2011-4-1-下午11:16:32
 */
@Controller
@RequestMapping("/we")
public class WeAction {
	private WeManager weManager;

	/**
	 * 获取本月水电详情列表
	 * @return
	 */
	@RequestMapping(value="/list",method=RequestMethod.GET)
	public @ResponseBody List<WeList> list() {
		List<WeList> wList = weManager.getByDate(DateUtil.getToday());
		return wList;
	}
	
	/**
	 * 修改所有水电单价信息
	 * @param wd
	 * @param model
	 * @return
	 */
	@RequestMapping(value="/define",method=RequestMethod.POST)
	public @ResponseBody Map<String,Object>
		define(WeDefine wd,Model model){
		Map<String,Object> result = new HashMap<String,Object>();
		result.put("success", true);
		try{
			weManager.updateDefine(wd);
		}catch(Exception e){
			result.put("success", false);
		}
		return result;
	}
	
	/**
	 * 修改一条水电信息
	 * @param wm
	 * @param model
	 * @return
	 */
	public @ResponseBody Map<String,Object>
		month(WeMonth wm,Model model){
		Map<String,Object> result = new HashMap<String,Object>();
		result.put("success", true);
		try{
			weManager.updateWeMonth(wm);
		}catch(Exception e){
			result.put("success", false);
		}
		return result;
	}

	@Resource(name="weManager")
	public void setWeManager(WeManager weManager) {
		this.weManager = weManager;
	}
}
